package nativeimg;

import java.io.File;
import java.util.Arrays;

public class ImageTools {

	// 强制从当前路径加载so文件，修改了jvm的配置比较危险，建议使用命令行代替
	// java -Djava.library.path=/jni/library/path
	static {
		File directory = new File("");
		String libpath = directory.getAbsolutePath();
		if (!Arrays.asList(System.getProperty("java.library.path").split(File.pathSeparator)).contains(libpath)) {
			System.setProperty("java.library.path",
					System.getProperty("java.library.path") + File.pathSeparator + libpath);
		}
		System.out.println("将so文件放到以下任意路径(仅对当前启动方式生效):");
		for(String path:System.getProperty("java.library.path").split(File.pathSeparator)){
			System.out.println(path);
		}
		try {
			final java.lang.reflect.Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
			boolean ass = sysPathsField.isAccessible();
			sysPathsField.setAccessible(true);
			sysPathsField.set(null, null);
			sysPathsField.setAccessible(ass);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}
	}

	static {
		System.loadLibrary("nativejpeg");
	}

	public native static boolean zoomJpeg(String path, String toPath, int maxWidth, int maxHeight, int quality);

}
